package com.leizhou.ccontroller;

import com.leizhou.pojo.User;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
/**
 * @author LT
 * @version 1.0.0
 * @ClassName PropController01.java
 * @Description TODO @ConfigurationProperties: java语言中的全部数据类型
 * @createTime 2020年04月16日 00:15:00
 * @ConfigurationProperties注解注入属性需要注意哪些问题？
 * 1. 所有属性都需要提供setter方法
 * 2. 属性名要与application.yml文件中key一致
 */
/** 第一种方式: 注入属性 */
@RestController
// @ConfigurationProperties(prefix = "my")
public class PropController01 {
    private String host;
    private int port;
    private User user;
    private String[] address;
    private List<User> users;

    @GetMapping("/test1")
    public String test1(){
        System.out.println("=======test1=======");
        System.out.println("======test1=======");
        System.out.println("host = " + host);
        System.out.println("port = " + port);
        System.out.println("user = " + user);
        System.out.println("address = " + Arrays.toString(address));
        System.out.println("users = " + users);
        return "test1方法，访问成功！";
    }

    /**
     * 注入的属性必须提供setter方法
     * @param host
     */
    public void setHost(String host) {
        this.host = host;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setAddress(String[] address) {
        this.address = address;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }
}
